<template>
	<view>
		<jiazai v-if="isshow"></jiazai>
		<block v-else>
			<comment :Comment="hotComments" :Time="hotTime" :type="hotco" ></comment>
			<comment :Comment="newcomments" :Time="newTime" :type="newco" ></comment>
		</block>
	</view>
</template>

<script>
	import comment from '../../components/comment/comment/comment.vue';
	import jiazai from '../../components/home/jiazai/jiazai.vue'
	export default {
		components:{
			comment,
			jiazai
		},
		data() {
			return {
				playingId:0,
				playlistId:0,
				isshow:true,
				hotComments:[],
				hotTime:[],
				hotco:'hot',
				newco:'new',
				newcomments:[],
				newTime:[]
			}
		},
		onLoad(options) {
			const playingId=options.playingId;
			const playlistId=options.playlistId;
			this.playingId=playingId;
			this.playlistId=playlistId;
			if(playingId){
			  this.getMusicDiscussInfo(playingId,1);
			}else{
			  this.getMusicDiscussInfo(playlistId,2);
			}
			this.playingId=playingId;
			this.playlistId=playlistId;
		},
		onPullDownRefresh(){
			console.log("hanser")
			this.hotComments=[];
			this.hotTime=[];
			this.newcomments=[];
			this.newTime=[];
			let {playingId}=this;
			let {playlistId}=this;
			if(playingId){
			  this.getMusicDiscussInfo(playingId,1);
			}else{
			  this.getMusicDiscussInfo(playlistId,2);
			}	
		},
		methods: {
			async getMusicDiscussInfo(Id,way){
			    if(way==1){
			      let discussInfo=await this.request({url: this.bsurl+'comment/music?id='+Id});
			      this.hanlediscussInfo(discussInfo)
			    }else{
			      let discussInfo=await this.request({url: this.bsurl+'comment/playlist?id='+Id});
			      this.hanlediscussInfo(discussInfo)
			    }
				if(this.Finish()){
				  	setTimeout(()=>{
				  		this.isshow=false
				  	}, 1000);
				}	 
			},
			hanlediscussInfo(discussInfo){
			    let hotComments=discussInfo.hotComments.map(v=>{
			      return{
			        nickname:v.user.nickname,
			        pic:v.user.avatarUrl+'?param=60y60',
			        content:v.content,
			        likedCount:v.likedCount
			      }
			    })
			    let newcomments=discussInfo.comments.map(v=>{
			      return{
			        nickname:v.user.nickname,
			        pic:v.user.avatarUrl+'?param=60y60',
			        content:v.content,
			        likedCount:v.likedCount
			      }
			    })
			    let hotTime=discussInfo.hotComments.map(v=>this.formatDate(v.time));
			    let newTime=discussInfo.comments.map(v=>this.formatDate(v.time));
			    this.hotComments=hotComments;
			    this.newcomments=newcomments;
			    this.hotTime=hotTime;
			    this.newTime=newTime;
			},
			formatDate(now){
			    var Noday=new Date(now);
			    var year=Noday.getFullYear();  
			    var month=Noday.getMonth()+1;  
			    var date=Noday.getDate();      
			    let time=year+"年"+month+"月"+date+"日"
			    return time;
			},
			
		}
	}
</script>

<style lang="less" scoped>

</style>
